package com.firewolf.vue.verify;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;

/**
 * 作者：刘兴
 * 时间:19/3/6
 **/
@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private ImageCodeGenerator imageCodeGenerator;


    @GetMapping("/image")
    public void imagecode(HttpServletResponse response, HttpSession session) throws Exception {


        ImageCode imageCode = imageCodeGenerator.generatorImageCode();

        BufferedImage image = imageCode.getImage();
        ImageIO.write(image, "jpeg", response.getOutputStream());  //让前台展示图片

        session.setAttribute("IMAGE_CODE", imageCode); //保存起来用于后续认证

    }

}
